import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/refresh_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_index/viewmodel/room_admins_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_block_list_view_model.dart';
import 'package:module_business/module_my/viewmodel/my_collection_view_model.dart';

/**
 * 我的收藏主页
 */
class MyCollectionPage extends GetWidget<MyCollectionViewModel> {
  const MyCollectionPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PageWidget.build(
        builder: (MyCollectionViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              backgroundColor: ColorUtil.instance.color_transparent,
              titleStr: StringUtil.instance.My_collection,
              titleTextStyle: TextStyle(
                fontSize: PxUtil.instance.px_18,
                color: ColorUtil.instance.color_white,
                fontWeight: FontWeight.bold
              ),
            ),
            body: Container(
              width: PxUtil.instance.screenWidth,
              height: PxUtil.instance.screenHeight-PxUtil.instance.statusBarHeight
                  -PxUtil.instance.appBarHeight,
              padding: EdgeInsets.only(
                left: PxUtil.instance.px_15,
                right: PxUtil.instance.px_15,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(child: RefreshUtil.init(
                    model.refreshController,
                        ()=>model.onRefresh(pageCur: model?.page=1),
                        ()=>model.onRefresh(pageCur: model?.page+1),
                    _buildListUi(model),
                    physics: ClampingScrollPhysics(),
                    loadStatus: model?.loadStatus,
                    enablePullDown: true,
                    enablePullUp: true,
                    isCanMoreData: model?.isCanMoreData??true,
                    onReFreshFunction:()=>model.onRefresh(pageCur: model?.page=1),
                  ))
                ],
              ),
            ),
          );
        }
    );
  }

  Widget _buildListUi(MyCollectionViewModel model) {
    return ListView.builder(
        shrinkWrap: true,
        itemCount: model.myCollectionRooms?.length??0,
        itemBuilder: (BuildContext context,int index){
          var myCollectionRoomItem = model.myCollectionRooms[index];
          return InkWellButton(
            onPressed: ()=>model.toRoom(index),
            child: Container(
              padding: EdgeInsets.only(
                top: PxUtil.instance.px_12,
                bottom: PxUtil.instance.px_12,
              ),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                          color: ColorUtil.instance.color_879d9d9d,
                          width: PxUtil.instance.px_0d5
                      )
                  )
              ),
              child: Row(
                children: [
                  ImagesUtil.loadNetworkImage(
                    myCollectionRoomItem?.coverImg??'',
                    width: PxUtil.instance.px_78,
                    height: PxUtil.instance.px_78,
                    radius: BorderRadius.circular(PxUtil.instance.px_8),
                  ),
                  SizedBox(width: PxUtil.instance.px_10,),
                  Expanded(child: Container(
                    height: PxUtil.instance.px_78,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        Row(
                          children: [
                            Expanded(child: Text(
                              myCollectionRoomItem?.roomName??'',
                              style: TextStyle(
                                  fontWeight: FontWeight.w500,
                                  color: ColorUtil.instance.color_white,
                                  fontSize: PxUtil.instance.px_14
                              ),
                            ),),
                            ImagesUtil.loadAssetImage(
                                DrawableUtil.instance.icon_popular_num,
                                width: PxUtil.instance.px_16
                            ),
                            SizedBox(width: PxUtil.instance.px_2,),
                            Text(
                              '${myCollectionRoomItem?.charismaShow??0}',
                              style: TextStyle(
                                  fontWeight: FontWeight.w500,
                                  color: ColorUtil.instance.color_white,
                                  fontSize: PxUtil.instance.px_12
                              ),
                            )
                          ],
                        ),
                        Text(
                          '${StringUtil.instance.ID}：${myCollectionRoomItem?.roomCode??'0'}',
                          style: TextStyle(
                              fontWeight: FontWeight.w500,
                              color: ColorUtil.instance.color_half_white,
                              fontSize: PxUtil.instance.px_12
                          ),
                        ),
                        Row(
                          children: [
                            Expanded(child: Text(
                              myCollectionRoomItem?.roomSynopsis??'Welcome to room....',
                              style: TextStyle(
                                  fontWeight: FontWeight.w500,
                                  color: ColorUtil.instance.color_half_white,
                                  fontSize: PxUtil.instance.px_12
                              ),
                            ),),
                            InkWellButton(
                              onPressed: ()=>model.doCollectRoom(myCollectionRoomItem,index),
                              child: ImagesUtil.loadAssetImage(
                                  DrawableUtil.instance.icon_collect,
                                  width: PxUtil.instance.px_20,
                                  color: ColorUtil.instance.color_main

                              ),
                            ),
                          ],
                        ),

                      ],
                    ),
                  )),
                ],
              ),
            ),
          );
        }
    );
  }
}
